package org.vaadin.golfscoretracker;

import org.vaadin.appfoundation.persistence.facade.FacadeFactory;
import org.vaadin.golfscoretracker.data.Course;
import org.vaadin.golfscoretracker.data.Hole;
import org.vaadin.golfscoretracker.data.Player;

public class TestData {

    public static void createTestData() {
        // Courses
        for (int j = 1; j < random(3, 6); j++) {
            Course course = new Course();
            course.setName("Course " + j);

            for (int i = 0; i < random(1, 18); i++) {
                Hole hole = new Hole();
                hole.setPar(random(3, 5));
                hole.setCourse(course);
                hole.setLength(random(100, 560));
                course.addHole(hole);
            }

            FacadeFactory.getFacade().store(course);
        }

        // Players
        Player player = new Player();
        player.setName("Jack");
        FacadeFactory.getFacade().store(player);

        player = new Player();
        player.setName("Anthony");
        FacadeFactory.getFacade().store(player);

        player = new Player();
        player.setName("David");
        FacadeFactory.getFacade().store(player);

        player = new Player();
        player.setName("Samantha");
        FacadeFactory.getFacade().store(player);

        player = new Player();
        player.setName("Amanda");
        FacadeFactory.getFacade().store(player);
    }

    private static int random(int min, int max) {
        return min + (int) (Math.random() * 1000 % (max - min));
    }
}
